<?php
	$mysql = new mysqli("localhost","root","","yihe");
	if($mysql -> connect_error){
		exit ("数据库连接失败");
	}
	$flag = $_POST["flag"];
	switch ($flag) {
		case 'update':
		{
			update();
			break;
		}
		case 'select':
		{
			select();
			break;
		}
		
		default:
			
			break;
	}
	
	//<------------------------修改信息------------------->
	function update(){
		global $mysql;
		$user_neck_name = $_POST["user_neck_name"];
		$user_gender = $_POST["user_gender"];
		$user_birthday = $_POST["user_birthday"];
		$user_phone = $_POST["user_phone"];
		$update_sql = "update user_info set user_neckname = '{$user_neck_name}', user_gender = '{$user_gender}', user_birthday = '{$user_birthday}' where user_phone = '{$user_phone}'";
		$result = $mysql -> query($update_sql);
		if($result){
			echo "1";
		}else{
			echo "0";
		}
	}
	//<-----------------------查询信息------------------------->
	function select(){
		global $mysql;
		$user_phone = $_POST["user_phone"];
		$select_sql = "select user_neckname, user_gender, user_birthday from user_info where user_phone = '{$user_phone}'";
		$result = $mysql -> query($select_sql);
		if($result){
			$user_arr = array();
			while ($row = $result -> fetch_object()) {
				array_push($user_arr, $row);
			}
			echo json_encode($user_arr);
		}
	}
?>